<template>
  <el-dialog  title="导出订单" :close-on-click-modal="false"  :visible.sync="visible">
    <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="download()" label-width="120px">
      <el-form-item label="添加时间" style="margin-bottom: 8px;width: 400px">
        <el-date-picker
          v-model="dataForm.pay_time"
          type="datetimerange"
          align="right"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['08:00:00', '00:00:00']">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="订单状态" style="margin-bottom: 8px;width: 400px">
        <el-select v-model="dataForm.order_status" clearable placeholder="全部">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="快递渠道" style="margin-bottom: 8px;width: 400px">
        <el-select v-model="dataForm.shipping_id" clearable placeholder="全部">
          <el-option
            v-for="item in options1"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="poiHandle()">导出</el-button>
    </span>
  </el-dialog>
</template>

<script>
    export default {
        data () {
            return {
                options1: [{
                    value: '9',
                    label: 'EMS优惠线'
                }, {
                    value: '38',
                    label: '顺丰国际专线'
                }, {
                    value: '53',
                    label: '退国内圆通快递'
                }, {
                    value: '2',
                    label: 'DHL'
                }, {
                    value: '16',
                    label: '食品专线'
                }, {
                    value: '58',
                    label: '美国专线'
                }],
                options: [{
                    value: '0',
                    label: '未打包'
                }, {
                    value: '1',
                    label: '已打包'
                }, {
                    value: '2',
                    label: '已支付'
                }],
                value: '',
                value2: '',
                packages: [],
                visible: false,
                dataForm: {
                    pay_time: '',
                    order_status: '',
                    shipping_id: '',
                    orderId: 0,
                    outTrackingNumber: ''
                }
            }
        },
        methods: {
            init (id) {
                this.dataForm.orderId = id || 0
                this.visible = true
                this.$nextTick(() => {
                    this.$refs['dataForm'].resetFields()
                    if (this.dataForm.orderId) {
                        this.$http({
                            url: this.$http.adornUrl(`/order/v9order/info/${this.dataForm.orderId}`),
                            method: 'get',
                            params: this.$http.adornParams()
                        }).then(({data}) => {
                            if (data && data.code === 0) {
                                this.dataForm.shippingName = data.v9Order.shippingName
                                this.dataForm.outTrackingNumber = data.v9Order.outTrackingNumber
                                this.dataForm.orderSn = data.v9Order.orderSn
                                this.dataForm.specialId = data.v9Order.specialId
                                this.dataForm.postscript = data.v9Order.postscript
                                this.dataForm.addservices = data.v9Order.addservices
                                this.dataForm.name = data.v9Order.name
                                this.dataForm.country = data.v9Order.country
                                this.dataForm.mobile = data.v9Order.mobile
                                this.dataForm.city = data.v9Order.city
                                this.dataForm.province = data.v9Order.province
                                this.dataForm.zipcode = data.v9Order.zipcode
                                this.dataForm.address = data.v9Order.address
                                this.packages = data.data.packages
                            }
                        })
                    }
                })
            },
            // 表单提交
            poiHandle () {
                let time = this.dataForm.pay_time
                // eslint-disable-next-line one-var
                let start = '', end = ''
                // eslint-disable-next-line eqeqeq
                if (time != '' && time != null) {
                    start = time[0]
                    end = time[1]
                }
                if(this.dataForm.shipping_id==9){
                    window.location.href = this.$http.adornUrl(`/sys/operationtotal/download?pay_status=` + this.dataForm.order_status + '&shipping_id=' + this.dataForm.shipping_id + '&start=' + start + '&end=' + end)
                }
                if (this.dataForm.shipping_id==38){
                    window.location.href = this.$http.adornUrl(`/sys/operationtotal/SFData?pay_status=` + this.dataForm.order_status + '&shipping_id=' + this.dataForm.shipping_id + '&start=' + start + '&end=' + end)
                }
                if (this.dataForm.shipping_id==53){
                    window.location.href = this.$http.adornUrl(`/sys/operationtotal/YTData?pay_status=` + this.dataForm.order_status + '&shipping_id=' + this.dataForm.shipping_id + '&start=' + start + '&end=' + end)
                }
            }
        }
    }
</script>

